package study.函数式接口.使用问号extend泛型;

import study.函数式接口.Apple;
import study.函数式接口.Fruit;
import study.函数式接口.RedApple;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author 金贵权
 * @Date 2023/6/16 10:48
 **/
public class Demo01 {
    public static void main(String[] args) {
        /*extends只能get取值,不能添加数据,存放的值只能是Apple的子类和自身*/
        List<? extends Apple> list = new ArrayList<>();

        /*super用来put存值,最后不get取值,存放的值只能是Apple的子类和自身*/
        List<? super Apple> listSuper = new ArrayList<>();
        listSuper.add(new Apple(12));
        listSuper.add(new RedApple());
        Object object = listSuper.get(0);
        System.out.println(object);

        List<Apple> appleList = Arrays.asList(new Apple(13), new Apple(14), new Apple(15),new RedApple(12));
        list = appleList;
    }
}
